/*
 * Copyright (c) 2024 Black Sesame Technologies
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <gtest/gtest.h>
#include "dal/qos_policy.h"
#include "dal_cyclonedds/converter/StatusConverter.hpp"

TEST(ConvertInconsistentTopicStatusFromCycloneddsToDal, StatusConverter)
{
    dds_inconsistent_topic_status_t c_status;
    dal_inconsistent_topic_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    StatusConverter::GetInstance()->ConvertInconsistentTopicStatusFromCycloneddsToDal(&c_status,
                                                                                   &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
}

TEST(ConvertSampleLostStatusFromCycloneddsToDal, StatusConverter)
{
    dds_sample_lost_status_t c_status;
    dal_sample_lost_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    StatusConverter::GetInstance()->ConvertSampleLostStatusFromCycloneddsToDal(&c_status, &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
}

TEST(ConvertSampleRejectedStatusFromCycloneddsToDal, StatusConverter)
{
    dds_sample_rejected_status_t c_status;
    dal_sample_rejected_status_t d_status;
    c_status.last_reason = DDS_REJECTED_BY_INSTANCES_LIMIT;
    StatusConverter::GetInstance()->ConvertSampleRejectedStatusFromCycloneddsToDal(&c_status, &d_status);
    EXPECT_NE(d_status.last_reason, DAL_REJECTED_BY_SAMPLES_LIMIT);
    EXPECT_EQ(d_status.last_reason, DAL_REJECTED_BY_INSTANCES_LIMIT);
}

TEST(ConvertLivelinessLostStatusFromCycloneddsToDal, StatusConverter)
{
    dds_liveliness_lost_status_t c_status;
    dal_liveliness_lost_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    StatusConverter::GetInstance()->ConvertLivelinessLostStatusFromCycloneddsToDal(&c_status, &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
}

TEST(ConvertLivelinessChangedStatusFromCycloneddsToDal, StatusConverter)
{
    dds_liveliness_changed_status_t c_status;
    dal_liveliness_changed_status_t d_status;
    c_status.alive_count = 100l;
    c_status.not_alive_count = 200l;
    c_status.alive_count_change = 300l;
    c_status.not_alive_count_change = 400l;
    StatusConverter::GetInstance()->ConvertLivelinessChangedStatusFromCycloneddsToDal(&c_status,
                                                                                   &d_status);
    EXPECT_EQ(d_status.alive_count, c_status.alive_count);
    EXPECT_EQ(d_status.not_alive_count, c_status.not_alive_count);
    EXPECT_EQ(d_status.alive_count_change, c_status.alive_count_change);
    EXPECT_EQ(d_status.not_alive_count_change, c_status.not_alive_count_change);
}

TEST(ConvertOfferedDeadlineMissedStatusFromCycloneddsToDal, StatusConverter)
{
    dds_offered_deadline_missed_status_t c_status;
    dal_offered_deadline_missed_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    StatusConverter::GetInstance()->ConvertOfferedDeadlineMissedStatusFromCycloneddsToDal(&c_status, &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
}

TEST(ConvertRequestedDeadlineMissedStatusFromCycloneddsToDal, StatusConverter)
{
    dds_requested_deadline_missed_status_t c_status;
    dal_requested_deadline_missed_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    StatusConverter::GetInstance()->ConvertRequestedDeadlineMissedStatusFromCycloneddsToDal(&c_status, &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
}

TEST(ConvertOfferedIncompatibleQosStatusFromCycloneddsToDal, StatusConverter)
{
    dds_offered_incompatible_qos_status_t c_status;
    dal_offered_incompatible_qos_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    c_status.last_policy_id = DDS_ENTITYFACTORY_QOS_POLICY_ID;
    StatusConverter::GetInstance()->ConvertOfferedIncompatibleQosStatusFromCycloneddsToDal(&c_status,
                                                                                        &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
    EXPECT_NE(d_status.last_policy_id, DAL_TIMEBASEDFILTER_QOS_POLICY_ID);
    EXPECT_EQ(d_status.last_policy_id, DAL_ENTITYFACTORY_QOS_POLICY_ID);
}

TEST(ConvertRequestedIncompatibleQosStatusFromCycloneddsToDal, StatusConverter)
{
    dds_requested_incompatible_qos_status_t c_status;
    dal_requested_incompatible_qos_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    c_status.last_policy_id = DDS_ENTITYFACTORY_QOS_POLICY_ID;
    StatusConverter::GetInstance()->ConvertRequestedIncompatibleQosStatusFromCycloneddsToDal(&c_status,
                                                                                        &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
    EXPECT_NE(d_status.last_policy_id, DAL_TIMEBASEDFILTER_QOS_POLICY_ID);
    EXPECT_EQ(d_status.last_policy_id, DAL_ENTITYFACTORY_QOS_POLICY_ID);
}

TEST(ConvertPublicationMatchedStatusFromCycloneddsToDal, StatusConverter)
{
    dds_publication_matched_status_t c_status;
    dal_publication_matched_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    c_status.current_count = 10l;
    c_status.current_count_change = 20l;
    StatusConverter::GetInstance()->ConvertPublicationMatchedStatusFromCycloneddsToDal(&c_status,
                                                                                        &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
    EXPECT_EQ(d_status.current_count, c_status.current_count);
    EXPECT_EQ(d_status.current_count_change, c_status.current_count_change);
}

TEST(ConvertSubscriptionMatchedStatusFromCycloneddsToDal, StatusConverter)
{
    dds_subscription_matched_status_t c_status;
    dal_subscription_matched_status_t d_status;
    c_status.total_count = 100l;
    c_status.total_count_change = 200l;
    c_status.current_count = 10l;
    c_status.current_count_change = 20l;
    StatusConverter::GetInstance()->ConvertSubscriptionMatchedStatusFromCycloneddsToDal(&c_status,
                                                                                        &d_status);
    EXPECT_EQ(d_status.total_count, c_status.total_count);
    EXPECT_EQ(d_status.total_count_change, c_status.total_count_change);
    EXPECT_EQ(d_status.current_count, c_status.current_count);
    EXPECT_EQ(d_status.current_count_change, c_status.current_count_change);
}